package class202205.demo05.demo03;


import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.security.spec.PSSParameterSpec;

class Animal {
    public String name;
    public Animal(String name) {
        this.name = name;
    }
    public void eat(){
        System.out.println("吃饭饭！");
    }
    // 飞  跑  游泳    布恩那个把这些操作写在这里
}

interface IFlying{
    void fly();
}
interface IRunning{
    void run();
}
interface ISwimming{
    void swim();
}

class Cat extends Animal implements IRunning{

    public Cat(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name+"is cat 正在跑！");
    }
}

//狗  继承了Animal实现了 跑和游泳接口    先继承后实现   需要重写两接口的方法
class Dog extends Animal implements IRunning,ISwimming{
    public Dog(String name){
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name+"is dog 正在跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.name+"正在游泳！");
    }
}
class Robot implements IRunning{

    @Override
    public void run() {
        System.out.println("我是机器人，我在跑！");
    }
}
class Duck extends Animal implements IRunning,ISwimming,IFlying{

    public Duck(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name+"鸭子正在飞！");
    }

    @Override
    public void run() {
        System.out.println(this.name+"鸭子正在跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.name+"鸭子正在游泳！");
    }
}

public class TestDemo1 {
    public static void walk(IRunning iRunning){
        iRunning.run();
    }
    public static void fly(IFlying iFlying){
        iFlying.fly();
    }
    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }

    public static void main(String[] args) {
        //swim(new Dog("小狗"));
        Duck duck = new Duck("小鸭子");
        swim(duck);
        walk(duck);
        fly(duck);
    }

    public static void main2(String[] args) {
        walk(new Cat("mimi"));
        walk(new Dog("mimi2"));
        walk(new Robot());
    }

    public static void main1(String[] args) {
        Animal animal = new Cat("mimi");
        Animal animal2 = new Dog("mimi2");
        IRunning iRunning = new Cat("mimi");
        IRunning iRunning2 = new Dog("mimi2");
        ISwimming iSwimming2 = new Dog("mimi2");
    }
}

